package core

import grails.converters.JSON
import grails.converters.XML

class CountryController {
	def index() {
		def imageUrl = createLinkTo(dir:"images", file:"grails_logo.png").toString()
		println imageUrl 
		def max =25 //params.long('max')?:25
		def start = params.long('start')?:0
		[countries:Country.list(max: max, offset:start ),max:max ,start:start ,imageUrl:imageUrl]
	}

	def create(){
	}
	def save() {
		def country = new Country(params)
		if (country.save()) {
			flash.notice = "Country ${country.code}: is saved successfuly"
			redirect(action:'index')
		} else {
			flash.error = "Country ${country.code}: Failed to save"
			render view:'create', model:[country:country]
		}
	}
	def redi() {
		def list = [1, 5, 8]
		// redirects to the list action within the same controller
		//		redirect(action: list)
		//		redirect(controller: 'person', action: 'index')
		redirect(action: 'show', params:[id:170])
	}

	def show(long id) {
		[ country: Country.get(id)]
	}
	
}
